require('../../assets/css/index.less');
require("../../assets/fitness-font/iconfont.css");
require('./my.less');


// 底部导航
const nav = require('../../utils/nav');
nav.showNav('my');

// 引入axios
const axios = require('../../utils/axios.js');

// 引入window
const { $, g } = require('../../utils/dom')

/***
 * 加载事件
 */
$(function () {

    // 获取用户信息
    axios.get('/api/user/info').then((res) => {
        if (res.data.errno === 0) {
            let data = res.data.data;
            g('#portrait').src = data.imgUrl;
            g('#desc').textContent = data.sign;
            g('#nickname').textContent = data.nickName;
        }
    })

    /**
     * 打卡
     */
    g('#clockBtn').addEventListener('click', () => {
        axios.post('/api/user/clockIn').then(res => {
            if (res.data.errno === 0) {
                console.log('res.data :>> ', res.data);
                g('#day').textContent = +g('#day').textContent + 1;
                g('#clockBtn').textContent = '今日已打卡'
            }
        })
    })

    /**
     * 获取用户打卡信息
     */
    axios.get('/api/user/clockInInfo').then(res => {
        if (res.data.errno === 0) {
            g('#clockBtn').textContent = res.data.data.isClockIn ? '今日已打卡' : '今日打卡'
        }
    })

    /**
     * 运动数据
     */
    axios.get('/api/exercise').then(res => {
        if (res.data.errno === 0) {
            console.log('res.data :>> ', res.data);
            let data = res.data.data
            g('#mintue').textContent = data.sum7Duration
            g('#mintues').textContent = data.sum7Calorie
        }
    })
})